<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="sass/index.css"/>
		<script src="js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<header>
					<input type="search" value="搜索内容" class="txt"/><button class="btn">搜索</button>
		</header>
		<ul class="mine">
			<!--<li>
				<div class="left">
					<a href="">
						<img src="http://img7.doubanio.com\/img\/celebrity\/small\/43502.jpg"/>
					</a>
					
				</div>
				<div class="right">
					<h3>肖的申克救赎&nbsp;&nbsp;&nbsp; 9.6</h3>
					<p>原名：The Shawang Redempalt</p>
					<p>导演：</p>
					<p>主演：time</p>
					<p>类型</p>
					<p>年份</p>
				</div>
			</li>-->
		</ul>
	</body>
	<script type="text/javascript">
//		function fun(){
//			wi
//		}
		$.ajax({
			type:"get",
			url:"http://api.douban.com/v2/movie/top250",
			async:true,
			dataType:'jsonp',
			success:function(data){
//				console.log(data);
				//var arr=JSON.parse(data);
				//console.log(arr);
				//var obj=JSON.parse(data).subjects;
				var obj=data.subjects
//				console.log(obj);
				var html='';
				
				for(var i=0;i<obj.length;i++){
					html+='<li><div class="left"><a href="xq.html?id='+obj[i].id+'"><img src="'+obj[i].images.large+'"/></a></div><div class="right"><h3>'+obj[i].title+'&nbsp;&nbsp;&nbsp;'+obj[i].rating.average+'</h3><p>原名：'+obj[i].original_title+'</p><p>导演：'+getq(obj[i].directors,"name")+'</p><p>主演：'+obj[i].casts[0].name+'</p><p>类型:'+getq(obj[i].genres)+'</p><p>年份:'+obj[i].year+'</p></div></li>'
				}
				function getq(obj,att){
					var str='';
					if ( att !== undefined) {
						for(var i=0;i<obj.length;i++){
							
							str += obj[i][att]+"";
						}
						
					} else{
						for(var i=0;i<obj.length;i++){
							
							str += obj[i];
						}
					}
					return str;
				}
		
				$('.mine').append(html)
				
			}
		});
		
		
		$('.btn').click(function(){
			$.ajax({
				type:"get",
				url:"http://api.douban.com/v2/movie/search?",
				//	url: "http://api.douban.com/v2/movie/search?q="+$('.txt').val()+"",
				async:true,
				dataType:"jsonp",
				data:{"q":$('.txt').val()},
				success:function(data){
				console.log(data);
				//var arr=JSON.parse(data);
				//console.log(arr);
				//var obj=JSON.parse(data).subjects;
				var obj=data.subjects
				console.log(obj);
				var html='';
				
				for(var i=0;i<obj.length;i++){
					html+='<li><div class="left"><a href="xq.html?id='+obj[i].id+'"><img src="'+obj[i].images.large+'"/></a></div><div class="right"><h3>'+obj[i].title+'&nbsp;&nbsp;&nbsp;'+obj[i].rating.average+'</h3><p>原名：'+obj[i].original_title+'</p><p>导演：'+getq(obj[i].directors,"name")+'</p><p>主演：'+getq(obj[i].casts,"name")+'</p><p>类型:'+getq(obj[i].genres)+'</p><p>年份:'+obj[i].year+'</p></div></li>'
				}
				function getq(obj,att){
					var str='';
					if ( att !== undefined) {
						for(var i=0;i<obj.length;i++){
							
							str += obj[i][att]+" ";
						}
						
					} else{
						for(var i=0;i<obj.length;i++){
							
							str += obj[i];
						}
					}
					return str;
				}
				$('.mine').empty();
				$('.mine').append(html)
				
			}
			});
		})
	</script>
</html>
